package com.nicho.controller;

import java.util.Scanner;

import com.nicho.pojo.Teacher;
import com.nicho.service.TeacherService;
import com.nicho.util.InputTrans;
import com.nicho.util.MD5;
import com.nicho.view.TeacherPage;

/*
 * @Author: 姜东浩
 * @Date: 2021-11-12 08:34:15
 * @LastEditors: 姜东浩
 * @LastEditTime: 2021-11-16 08:42:44
 * @Description: 教师控制器类
 */
public class TeacherController {

    Teacher teacher = null;
    TeacherService teacherService = new TeacherService();
    Scanner sc = new Scanner(System.in);

    /**
     * @description: 教师登录验证
     * @param {String} userId
     * @param {String} password
     * @author: 姜东浩
     */
    public void login(String userId, String password) {

        // 将传进来的账号密码封装为一位教师对象
        teacher = new Teacher(userId, password);

        // 登录成功显示首页视图，否则提示登陆失败
        if (teacherService.teacherLogin(teacher) != null) {
            TeacherPage.showLoginSuccess();
        } else {
            System.out.println("登录失败");
        }

    }

    /**
     * @description: 修改教师密码
     * @return 修改密码操作结束后的对应提示信息
     * @author: 姜东浩
     */
    public String updatePassword() {

        System.out.print("请输入新密码：");
        return teacherService.updatePassword(MD5.md5(sc.next()));

    }

    /**
     * @description: （全部信息）打印此教师管理的学生集合
     * @param {ArrayList<Student>} myStudentList
     * @author: 姜东浩
     */    
    public void printMyStudentListAM() {
        teacherService.printMyStudentListAM(teacherService.getMyStudentList());
    }

    /**
     * @description: （重点信息）打印此教师管理的学生集合
     * @param {ArrayList<Student>} myStudentList
     * @author: 姜东浩
     */    
    public void printMyStudentList() {
        teacherService.printMyStudentList(teacherService.getMyStudentList());
    }

    /**
     * @description: 获取自己所教课程信息
     * @return 如果在授课返回自己所教课程信息，否则返回无在授课程
     * @author: 姜东浩
     */
    public String catMyTeachCourse(){

        return teacherService.catMyTeachCourse();
        
    }

    /**
     * @description: 登分
     * @return 操作后的提示信息
     * @author: 姜东浩
     */    
    public String addGrade(){

        teacherService.printMyStudentList(teacherService.getMyStudentList());
        System.out.println("输入exit退出登分页面");
        System.out.print("请输入学生ID：");
        String tsc = sc.next();
        if(tsc.equals("exit")){
            return "";
        }
        if(teacherService.existStudentById(tsc)!=null){
            System.out.print("请输入分数：");
            double grade = InputTrans.transitionToDouble(sc.next());
            if(grade==-1){
                return "成绩类型与要求不符，登分失败";
            }
            return teacherService.addGrade(tsc,grade);
        }else{
            return "未找到此学生";
        }

    }

}